{#
   flash notification
#}

{% macro flashes() %}
    {% for type, flashes in app.session.flashbag.all() %}
        <div class="alert alert-{{ type }}" role="{{ type }}">
            <ul class="list-unstyled">
                {% for flash in flashes %}
                <li>{{ flash }}</li>
                {% endfor %}
            </ul>
        </div>
    {% endfor %}
{% endmacro %}

{% macro alert(text, type) %}
    {% set type = 'alert-' ~ type|default('info') %}

    {% if text|default %}
        <div class="alert {{ type }}">
            {% if text is iterable %}
                <ul class="form-type-errors list-unstyled">
                    {% for line in text %}
                        <li>
                            <p class="text-{{ type }}">
                                {{ line.message|trans(line.messageParameters) }}
                            </p>
                        </li>
                    {% endfor %}
                </ul>
            {% else %}
                {{ text|trans }}
            {% endif %}
        </div>
    {% endif %}

{% endmacro %}

{% macro danger(text) %}
    {% from _self import alert %}
    {{ alert(text, 'danger') }}
{% endmacro %}


{% macro error(text) %}
    {% from _self import danger %}
    {{ danger(text) }}
{% endmacro %}

{% macro warning(text) %}
    {% from _self import alert %}
    {{ alert(text, 'warning') }}
{% endmacro %}

{% macro success(text) %}
    {% from _self import alert %}
    {{ alert(text, 'success') }}
{% endmacro %}

{% macro info(text) %}
    {% from _self import alert %}
    {{ alert(text, 'info') }}
{% endmacro %}
